package com.sansan.qiangji.service.impl.system;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sansan.qiangji.entity.system.User;
import com.sansan.qiangji.form.system.user.UserListForm;
import com.sansan.qiangji.mapper.system.UserMapper;
import com.sansan.qiangji.service.inter.system.UserService;
import com.sansan.qiangji.utils.pageUtils.PageResult;
import com.sansan.qiangji.utils.pageUtils.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    private UserMapper userMapper;

    @Resource
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public PageResult<User> userList(UserListForm userListForm) {
        int pageNum = userListForm.getPageNum();
        int pageSize = userListForm.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        User user = new User();
        user.setUserName(userListForm.getUserName());
        user.setUserStatus(userListForm.getUserStatus());
        List<User> users = userMapper.userList(user);
        return PageUtil.getPageResult(new PageInfo<>(users));
    }

    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }

    @Override
    public User findByUserId(Integer userId) {
        return userMapper.findByUserId(userId);
    }

    @Override
    public User findByUserName(String userName) {
        return userMapper.findByUserName(userName);
    }

    @Override
    public int deleteById(Integer userId) {
        return userMapper.deleteById(userId);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }
}
